package com.zjitc.p3.demo1;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/14 14:03
 * @description:
 */
@Aspect
public class AspectDemo {

  @Pointcut("execution(* com.zjitc.p3.demo1.A.a())")
  public void pointcutA(){}

  @Pointcut("execution(* com.zjitc.p3.demo1.A.b())")
  public void pointcutB(){}

  @Before("pointcutA()")
  public void beforeA(){System.out.println("init before a");}

  @After("pointcutA()")
  public void afterA(){System.out.println("destroy after a");}

  @AfterThrowing("pointcutB()")
  public void whenException(){System.out.println("error happened");}

  @Around("execution(* com.zjitc.p3.demo1.A.c())")
  public void around(ProceedingJoinPoint jp) throws Throwable{
    System.out.println(jp.getSignature().getName());
    jp.proceed();
  }
}
